﻿// Copyright (c) 2011 Matthew D Martin
// MIT or MS-PL License as you elect, please see root directory for text of licenses.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Dataglot
{
    /// <summary>
    /// For executing simple, parameterless sql using an OleDB or ODBC connection
    /// </summary>
    /// <remarks>
    /// Support s
    /// 
    /// <list type="bullet">
    /// <item>
    /// Namespaces, use {$ns}
    /// </item>
    /// 
    /// </list>
    /// 
    /// 
    /// </remarks>
    public class ParameterlessCommand : GenericCommand
    {
        public ParameterlessCommand(DataFactory targetFactory):base(targetFactory)
        {

        }

        public int Execute(string sql)
        {
            if (string.IsNullOrEmpty(sql))
                throw new ArgumentException("required argument 'sql' is null or empty");

            sql = sql.Replace("{$ns}", config.Namespace());

            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            return command.ExecuteNonQuery();
        }

        public DbDataReader ExecuteReader(string sql)
        {
            if(string.IsNullOrEmpty(sql))
                throw new ArgumentException("required argument 'sql' is null or empty");

            sql = sql.Replace("{$ns}", config.Namespace());

            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            return command.ExecuteReader();
        }
    }
}
